package org.example.servlet_01.request;

import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

/**
 * 获取请求行数据各个属性
 */

@WebServlet("/RequestDemo1")
public class RequestDemo1 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response){
        //1.获取请求方式：GET
        String method = request.getMethod();
        System.out.println("请求方式："+method);

        //2.获取虚拟目录：/bdp
        String contextPath = request.getContextPath();
        System.out.println("虚拟目录："+contextPath);

        //3. 获取Servlet路径：/RequestDemo1
        String servletPath = request.getServletPath();
        System.out.println("Servlet路径："+servletPath);

        //4. 获取Get方式请求参数：name=zhangsan
        String queryString  = request.getQueryString();
        System.out.println("Get方式请求参数："+queryString);

        //5.获取请求URI：/bdp/RequestDemo1
        String requestURI = request.getRequestURI();
        System.out.println("请求URI："+requestURI);
        StringBuffer requestURL = request.getRequestURL();
        System.out.println("请求URL："+requestURL);

        //6.获取协议及版本
        String protocol = request.getProtocol();
        System.out.println("协议及版本："+protocol);

        //7. 获取客户机IP
        String remoteAddr = request.getRemoteAddr();
        System.out.println("客户机IP："+remoteAddr);

        //8. 获取客户机主机名
        String remoteHost = request.getRemoteHost();
        System.out.println("客户机主机名："+remoteHost);
    }
}
